package com.fgi.interview.test.geekbang;

import com.sun.xml.internal.bind.v2.TODO;

import java.util.Objects;

/**
 * @author HanXu
 * @date 2023/9/18
 **/
public class MerchandiseV2 {
    private String name;
    private String id;
    private int count;
    private double soldPrice;
    private double purchasePrice;

    public MerchandiseV2(String name, String id, int count, double soldPrice, double purchasePrice) {
        this.name = name;
        this.id = id;
        this.count = count;
        this.soldPrice = soldPrice;
        this.purchasePrice = purchasePrice;
    }

    public MerchandiseV2() {
    }

    // TODO hashCode 和equals 是我们最常覆盖的两个方法
    // TODO 覆盖的原则是，equals为true, hashCode就应该相等。这是一种约定俗成的规范
    // TODO 即equals为t rue是hashCode相等的充分非必要条件，hashCode相等 是equals为t rue的必要不充分条件
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof MerchandiseV2)) return false;
        MerchandiseV2 that = (MerchandiseV2) o;
        return getCount() == that.getCount()
                && Double.compare(that.getSoldPrice(), getSoldPrice()) == 0
                && Double.compare(that.getPurchasePrice(), getPurchasePrice()) == 0
                && getName().equals(that.getName()) && getId().equals(that.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getName(), getId(), getCount(), getSoldPrice(), getPurchasePrice());
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getSoldPrice() {
        return soldPrice;
    }

    public void setSoldPrice(double soldPrice) {
        this.soldPrice = soldPrice;
    }

    public double getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(double purchasePrice) {
        this.purchasePrice = purchasePrice;
    }
}
